/*
 * @Author: zhangfeng
 * @Date: 2022-09-06 16:02:42
 * @LastEditTime: 2023-12-27 18:41:08
 * @LastEditors: zhangfeng
 * @Description:
 * @FilePath: \nodeapi\src\model\user.model.js
 * © 2023 张峰，All rights reserved.
 */
const { DataTypes } = require("sequelize");

const seq = require("../db/seq");
const Role = require("./role.model");
const Roleuser = require("./role-user.model");
// 创建模型

const User = seq.define(
  "zd_user",
  {
    user_name: {
      type: DataTypes.STRING,
      allowNull: false,
      unique: true,
      comment: "用户名",
    },
    password: {
      type: DataTypes.STRING,
      allowNull: false,
      comment: "密码",
    },
    is_admin: {
      type: DataTypes.BOOLEAN,
      allowNull: false,
      defaultValue: 0,
      comment: "是否为管理员，默认为0（不是管理员）",
    },
  }
  // 开启软删除
  // {
  //   paranoid: true,
  // }
  // 去掉默认的时间戳
  //  ,{
  //    timestamps:false
  //  }
);
// 创建数据表
//  User.sync({force:true})
User.belongsToMany(Role, { through: Roleuser, foreignKey: "userId" });
Role.belongsToMany(User, { through: Roleuser, foreignKey: "roleId" });
module.exports = User;
